import * as types from './mutation-types'

const matutations = {
  [types.SET_NAV](state, nav) {
    nav.menus.forEach(item => {
      item.show = false
    })
    state.nav = nav
  },
  [types.SET_NAV_STATE](state, i) {
    let newNav = state.nav
    newNav.menus[i].show = !newNav.menus[i].show
    state.nav = newNav
  },
  [types.SET_indexData](state, data) {
    state.indexData = data
  },
  [types.CLEAR_companyNewsData](state) {
    state.companyNewsData = {
      result: []
    }
  },
  [types.SET_detail](state, data) {
    state.detail = data
  },
  [types.CLEAR_detail](state) {
    state.detail = null
  },
  [types.SET_companyNewsData](state, data) {
    if (state.companyNewsData.result.length) {
      let result = state.companyNewsData.result.concat(data.result)
      state.companyNewsData = {
        ...state.companyNewsData,
        result
      }
    } else {
      state.companyNewsData = data
    }
  },
  [types.SET_BOTTOM_NAV_SATATE](state, flag) {
    state.hasBottomNav = flag
  },
  [types.SET_ARROW_BTN_STATE](state, flag) {
    state.showDownArrow = flag
  },
  [types.SET_SIDE_MENU_STATE](state, flag) {
    state.sideMenuShow = flag
  },
  [types.SET_productDetail](state, data) {
    state.productDetail = data
  },
  [types.SET_wxSdk](state, data) {
    state.wxSdk = data
  }
}

export default matutations
